package Friday.th2;
public class Bank_Pro {//主类
    public static void main(String[] args) {
        //创建建设银行对象和大连银行对象
        ConstructionBank bank_construction=new ConstructionBank();
        BankOfDalian bank_dalian=new BankOfDalian();
        //自定义两个银行的年利率和日利率
        ConstructionBank.日利率=0.0005;
        BankOfDalian.日利率=0.0004;
        bank_construction.年利率=0.0125;
        bank_dalian.年利率=0.0125;
        //初始化在两个银行存的钱数和时间
        bank_construction.savedMoney=8000;
        bank_dalian.savedMoney=8000;
        bank_construction.year=8.236;
        bank_dalian.year=8.236;
        //计算利息
        System.out.println("存放在建设银行时获得的利息:"+bank_construction.computerInterest());
        System.out.println("存放在大连银行时获得的利息:"+bank_dalian.computerInterest());
    }
}
//父类:Bank
class Bank{
    public int savedMoney,year;
    public double interest,年利率;
    public double computerInterest(){
        //计算整年数的利息
        return interest=savedMoney*year*年利率;
    }
}
//子类1:建设银行
class ConstructionBank extends Bank{
    public double year;
    public static double 日利率;
    public double computerInterest(){
        //将年数的整数部分赋值给父类中被隐藏的year
        super.year=(int)year;//强制类型转换
        //利息总和为年利息加剩余的天利息
        return interest=super.computerInterest()+((year-super.year)*1000)*savedMoney*日利率;
    }
}
//子类2:大连银行
class BankOfDalian extends Bank{
    public double year;
    public static double 日利率;
    public double computerInterest(){
        super.year=(int)year;
        return interest=super.computerInterest()+((year-super.year)*1000)*savedMoney*日利率;
    }
}